﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Club
{
    public partial class _Default : System.Web.UI.Page
    {
        string prepage = "Main.aspx";
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (Request.QueryString["prepage"] != null)
            {
                prepage = Request.QueryString["prepage"];
            }
            this.txtUserID.Focus();
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                DAL.User user = new DAL.User();
                user.Name = txtUserID.Text;
                user.Password = txtPassword.Text;
                BLL.ValidateUser validateUser = new BLL.ValidateUser();
                user = validateUser.validate(user);
                if (user != null)
                {
                    Dictionary<string, object> sessionVar = (Dictionary<string, object>)Session["vars"];
                    sessionVar["userVar"] = user;
                    Session["vars"] = sessionVar;
                    DateTime? l_lastLogout= user.UpdateLogin(user.Id, Request.ServerVariables["REMOTE_ADDR"] as string);
                    Session["LastLogout"] = l_lastLogout;
                }
                Response.Redirect(prepage);
            }
            catch (Exception ex)
            {
                WebCommon.ShowMsg(Response, ex.Message);
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("RegisterMember.aspx");
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {

        }
    }
}
